/**
 * Created by oneminute on 2014/4/26.
 */

var moment = require("moment");
var lz = require("../utils/modules")();

function Commodity(_opts) {
    lz.Persistent.call(this, _opts);
    if (!_opts) _opts = {};
    this.__properties.pushArray([
        { name: "id", value: _opts.id || "" },
        { name: "uid", value: _opts.uid || "" },
        { name: "description", value: _opts.description || "" },
        { name: "price", value: _opts.price || 0 },
        { name: "onsale", value: _opts.onsale || false },
        { name: "publishDate", value: moment().format(lz.Config.datetimeFormat) },
        { name: "photos", value: _opts.photos || [] }
    ]);
    this.__initProperties();
    this.__collection = lz.Config.db.arango.commodities;
    this.__aql = lz.Config.db.arango.aqls.GET_OBJECT_BY_PROPERTY;
}

require("util").inherits(Commodity, lz.Persistent);

Commodity.prototype.getInfo = function (_imgPrefix) {
    var imgPrefix = _imgPrefix || 't';
    var obj = this.getFields(['id', 'uid', 'description', 'price', 'onsale', 'publishDate', 'photos']);
    /*obj.photos = [];
    this.photos.forEach(function (_photo) {
        obj.photos.push(lz.ImageManager.getPhoto(_photo, imgPrefix));
    });*/
    return obj;
};

exports = module.exports = Commodity;